package com.xiaolin.springsecurity.model;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author xiaolin
 * @Description 自定义登录用户
 * @email xiaolin@gmail.com
 * @date 2024/5/5 15:42
 */
public class CustomUserDetails extends SystemUser implements UserDetails {
    private List<GrantedAuthority> authorities = Collections.singletonList(new SimpleGrantedAuthority("ROLE_common"));

    public CustomUserDetails(SystemUser systemUser) {
        super(systemUser.getId(), systemUser.getUsername(), systemUser.getPwd(), systemUser.getGender());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return super.getPwd();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
